package org.vectrics.recruiter.struts.tag;

import org.vectrics.common.html.Table;
import org.vectrics.company.Company;
import org.vectrics.company.CompanyPerson;
import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.user.CandidateInfo;
import org.vectrics.user.Person;

/**
 * @author mmoore
 */
public class UserBufferForPersonTag extends UserBufferTag {

	private static final long serialVersionUID = 6691438831757039433L;
	
	private String personId = null;
    	  
    protected Person getPerson() {
        Long personId = new Long(this.personId);
        Person person = CoreServiceLocator.getPersonService().findPersonById(personId);
        return(person);
    }
    
    protected void createJobBufferContent(Table contentTable, Job jobForBuffer) {
    	ThreadProperties.getSession().clear();
    	CandidateInfo candidate = RecruitServiceLocator.getRecruitUserService().findCandidateInfo(this.getPerson());
    	jobForBuffer = RecruitServiceLocator.getJobProvider().findJob(jobForBuffer.getId());
    	CompanyPerson employee = RecruitServiceLocator.getCompanyService().findEmployeeForIdPerson(this.getPerson().getId());
        if (((candidate == null) || (jobForBuffer.findJobCandidate(candidate) == null)) && (employee==null)) {
            String href = this.getContextPath() + "/admin/jobs/candidate/add.do?jobId=" + jobForBuffer.getId() 
	        + "&userId=" + getPerson().getId(); 
            this.makeLinkRow(contentTable, "Make candidate", href); 
        }
    }
    
    protected void createCompanyBufferContent(Table contentTable, Company companyForBuffer) {
        CompanyPerson companyPerson = CoreServiceLocator.getCompanyService().findCompanyPerson(companyForBuffer, getPerson());
        if (companyPerson == null) {
            String href = this.getContextPath() + "/admin/company/person/add.do?companyId=" + companyForBuffer.getId() 
	        + "&personId=" + getPerson().getId(); 
            this.makeLinkRow(contentTable, "Make Associate", href); 
        }
    }
    
    protected void createPersonBufferContent(Table contentTable, Person personForBuffer) {
    }

    /**
     * @return Returns the personId.
     */
    public String getPersonId() {
        return personId;
    }
    /**
     * @param personId The personId to set.
     */
    public void setPersonId(String personId) {
        this.personId = personId;
    }
    
}
